home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / recover / recoverPreparedTrans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.7 KB  |  229 lines

  1. /*
  2.  *   $RCSfile: recoverPreparedTrans.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:55 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "link.h"
  53. #include "lsn.h"
  54. #include "latch.h"
  55. #include "bf.h"
  56. #include "volume.h"
  57. #include "openlog.h"
  58. #include "trans.h"
  59. #include "openlog.h"
  60. #include "logrecs.h"
  61. #include "threadstate.h"
  62. #include "trans_extfuncs.h"
  63. #include "trans_intfuncs.h"
  64. #include "recover_intfuncs.h"
  65. #include "lm_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_globals.h"
  68. #include "thread_funcs.h"
  69. #include "thread_globals.h"
  70. #include "trans_globals.h"
  71. #include "recover_globals.h"
  72. #include "distr.h"
  73. #include "distr_globals.h"
  74.  
  75.  
  76. static 
  77.  void
  78. updateOpenLog(
  79.     register    TRANSREC    *transRec
  80. )
  81. {
  82.     register    TRANSREC    *currentTrans;
  83.     register    OPENLOG        *openLog;
  84.  
  85.     TRACE(TR_TRANS|TR_RECOVER, TR_LEVEL_1);
  86.  
  87.     /*
  88.      *    update the TransInfo.tidSequence
  89.      */
  90.     if (transRec->tid >= TransInfo.tidSequence ) {
  91.  
  92.         TransInfo.tidSequence = transRec->tid + 1;
  93.     }
  94.  
  95.     /*
  96.      *    update ActiveLogSpace
  97.      */
  98.     ActiveLogSpace += transRec->logSpace;
  99.  
  100.     /*
  101.      *  get a pointer to the open log
  102.      */
  103.     openLog = &OpenLog;
  104.  
  105.     if (LIST_EMPTY( &(openLog->activeList))) {
  106.  
  107.         /*
  108.          *    just move this 
  109.          */
  110.         listEnq(&(openLog->activeList), &(transRec->logActiveList));
  111.     }
  112.     else {
  113.         /*
  114.           *  get a pointer to the first transaction on the log list
  115.           */
  116.         currentTrans = (TRANSREC *)FIRST_LIST_ELEMENT(&(openLog->activeList));
  117.         while ((currentTrans != NULL) &&
  118.                (compareLSN(&(currentTrans->firstLSN), &(transRec->firstLSN)) <= 0)) {
  119.             currentTrans = (TRANSREC *)NEXT_LIST_ELEMENT(&(currentTrans->logActiveList));
  120.         }
  121.  
  122.         if (currentTrans == NULL) {
  123.             /*
  124.              *    put the item last on the list
  125.              */
  126.             listEnq(&(openLog->activeList), &(transRec->logActiveList));
  127.         }
  128.         else {
  129.             /*
  130.              *    put it before the current element
  131.              */
  132.             listInsertBefore(&(currentTrans->logActiveList), &(transRec->logActiveList));
  133.         }
  134.     }
  135. }
  136.  
  137.  void
  138. recoverPreparedTrans ()
  139. {
  140.  
  141.     OPENLOG        *openLog;
  142.     TRANSREC    *transRec;        /* current transaction    */
  143.     int        maxFork;        /* max forked undo threads*/
  144.  
  145.     TRACE(TR_TRANS|TR_RECOVER, TR_LEVEL_1);
  146.  
  147.     /*
  148.      *  get a pointer to the open log
  149.      */
  150.     openLog = &OpenLog;
  151.  
  152.     /*
  153.      *    check if enough threads are available to handle
  154.      *    each of the prepared transactions
  155.      */
  156.     maxFork = NumThreads-CONST_THREADS;
  157.  
  158.     if (maxFork < numActiveServerDistrTrans) {
  159.         fprintf(sm_ErrorStream, "SERVER ERROR: insufficient threads to perform undo phase\n");
  160.         SM_ERROR(TYPE_FATAL, esmNOFREETHREAD);
  161.     }
  162.  
  163.     /* proceed down the list */
  164.     transRec = (TRANSREC *) FIRST_LIST_ELEMENT( &ServerDistrTransList );
  165.     while (transRec != NULL)    {
  166.  
  167.         /*
  168.          *  check the entry magic number
  169.          */
  170.         CHECK_TRANSREC_MAGIC(transRec);
  171.  
  172.         /*
  173.          *    update the Openlog activeList
  174.          */
  175.         updateOpenLog(transRec);
  176.  
  177.         /* fork a thread to handle the transaction */
  178.         SM_ASSERT(LEVEL_3, sizeof(FOUR) == sizeof(transRec));
  179.         threadFork(T_PARENT, (PFI) recoverServerPreparedTrans, 1, (FOUR*) &(transRec));
  180.  
  181.         /* get the next transaction */
  182.         transRec = (TRANSREC *) NEXT_LIST_ELEMENT( &(transRec->distrTransList) );
  183.  
  184.     }
  185.  
  186.     /* proceed down the list */
  187.     transRec = (TRANSREC *) FIRST_LIST_ELEMENT( &CoordDistrTransList );
  188.     while (transRec != NULL)    {
  189.         /*
  190.          *  check the entry magic number
  191.          */
  192.         CHECK_TRANSREC_MAGIC(transRec);
  193.  
  194.         /*
  195.          *    update the Openlog activeList
  196.          */
  197.         updateOpenLog(transRec);
  198.  
  199.         /* get the next transaction */
  200.         transRec = (TRANSREC *) NEXT_LIST_ELEMENT( &(transRec->distrTransList) );
  201.     }
  202.  
  203.     /*
  204.      *    initialize numPrevActiveCoordDistrTrans 
  205.      */
  206.     numPrevActiveCoordDistrTrans = numActiveCoordDistrTrans;
  207.  
  208.     /*
  209.      *    set the OpenLog fields
  210.      */
  211.     
  212.     /*
  213.      *    get a pointer to the new first transaction record
  214.      */
  215.     if ((transRec = (TRANSREC *)FIRST_LIST_ELEMENT(&(openLog->activeList))) != NULL) {
  216.  
  217.         CHECK_TRANSREC_MAGIC(transRec);
  218.  
  219.         /*
  220.          *    update the position information of the new last record
  221.          */
  222.         openLog->activePid    = transRec->firstLogPid;
  223.         openLog->activeUnique = transRec->logUnique;
  224.         openLog->activeLSN    = transRec->firstLSN.offset;
  225.         TRPRINT(TR_LOG, TR_LEVEL_2, ("new last pid:%d lsn:%d",
  226.                 openLog->activePid, openLog->activeLSN));
  227.     }
  228. }
  229.